package com.hn.shiroredis.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试类
 *
 */
@RestController
@RequestMapping("/")
public class TestController {

    /**
     * hello word
     * @autor zhu
     * @return
     */
    @GetMapping("/hello")
    public String hello(){
        return "hello word";
    }

    @GetMapping("/login")
    public String login(String username, String password){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
        try {
            subject.login(usernamePasswordToken);
        } catch (AuthenticationException e) {
            return "用户名或密码错误";
        }
        return "登录成功";
    }
}
